﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace Maniac
{
    class ToolStripDatePicker : ToolStripControlHost
    {
        public ToolStripDatePicker() : base(new DateTimePicker()) { }
        public DateTimePicker DateTimePickerControl
        {
            get
            {
                return Control as DateTimePicker;
            }
        }
        public DateTime Value
        {
            get
            {
                return DateTimePickerControl.Value;
            }
            set
            {
                DateTimePickerControl.Value = value;
            }
        }
        public DateTimePickerFormat Format
        {
            get
            {
                return DateTimePickerControl.Format;
            }
            set
            {
                DateTimePickerControl.Format = value;
            }
        }
        public string CustomFormat
        {
            get
            {
                return DateTimePickerControl.CustomFormat;
            }
            set
            {
                DateTimePickerControl.CustomFormat = value;
            }
        }
        public System.Drawing.Point Location
        {
            get
            {
                return DateTimePickerControl.Location;
            }
            set
            {
                DateTimePickerControl.Location = value;
            }
        }
        
        public string Text
        {
            get
            {
                return DateTimePickerControl.Text;
            }
            set
            {
                DateTimePickerControl.Text = value;
            }
        }
        public int TabIndex
        {
            get
            {
                return DateTimePickerControl.TabIndex;
            }
            set
            {
                DateTimePickerControl.TabIndex = value;
            }
        }
        protected override void OnSubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);
            DateTimePicker dateTimePickerControl = (DateTimePicker)control;
            dateTimePickerControl.ValueChanged += new EventHandler(OnValueChanged);

        }
        protected override void OnUnsubscribeControlEvents(Control control)
        {
            base.OnUnsubscribeControlEvents(control);
            DateTimePicker tvdPicker = (DateTimePicker)control;
            tvdPicker.ValueChanged -= new EventHandler(OnValueChanged);
        }
        public event EventHandler ValueChanged;

        void OnValueChanged(object sender, EventArgs e)
        {
            if (ValueChanged != null)
            {
                ValueChanged(this, e);
            }
        }
    }
}
